<template>
	<div v-if="show">
		<el-container class="layout-container-demo" style="height: 700px">
			<el-aside width="200px">
				<el-scrollbar>
					<el-menu :default-openeds="['1','2']" router>
						<el-sub-menu index="1">
							<template #title>
								<el-icon>
									<message />
								</el-icon>营销管理
							</template>
							<el-menu-item-group>
								<template #title>销售机会</template>
								<el-menu-item index="/sc/add">增加销售机会</el-menu-item>
								<el-menu-item index="/sc/list">查询销售机会</el-menu-item>
							</el-menu-item-group>
							<el-menu-item-group title="销售计划">
								<el-menu-item index="/sc/devlist">我的销售机会</el-menu-item>
								<el-menu-item index="/sc/devlistAll">查询销售机会</el-menu-item>
							</el-menu-item-group>
						</el-sub-menu>
						<el-sub-menu index="2">
							<template #title>
								<el-icon>
									<icon-menu />
								</el-icon>客户管理
							</template>
							<el-menu-item-group>
								<template #title>客户信息</template>
								<el-menu-item index="/sc/custmerlist">查询客户信息</el-menu-item>
							</el-menu-item-group>
							<el-menu-item-group title="客户服务">
								<el-menu-item index="2-3">增加客户服务</el-menu-item>
								<el-menu-item index="/sc/Contact">查询客户服务</el-menu-item>
							</el-menu-item-group>
						</el-sub-menu>
						<el-sub-menu index="3">
							<template #title>
								<el-icon>
									<setting />
								</el-icon>报表管理
							</template>
							<el-menu-item-group>
								<template #title>销售机会统计</template>
								<el-menu-item index="3-1">客户来源统计</el-menu-item>
								<el-menu-item index="3-2">机会状态统计</el-menu-item>
							</el-menu-item-group>
						</el-sub-menu>
					</el-menu>
				</el-scrollbar>
			</el-aside>

			<el-container>
				<el-header style="text-align: right; font-size: 12px">
					<div class="toolbar">
						<el-dropdown>
							<el-icon style="margin-right: 8px; margin-top: 1px">
								<setting />
							</el-icon>
							<template #dropdown>
								<el-dropdown-menu>
									<el-dropdown-item>View</el-dropdown-item>
									<el-dropdown-item>Add</el-dropdown-item>
									<el-dropdown-item>Delete</el-dropdown-item>
								</el-dropdown-menu>
							</template>
						</el-dropdown>
						<span>{{proxy.$uName.value}}</span>
					</div>
				</el-header>

				<el-main>
					<router-view></router-view>
				</el-main>
			</el-container>
		</el-container>
	</div>
	<div v-else>
		<el-form label-width="100px" v-model="user" style="max-width: 460px">
			<el-form-item label="用户名">
				<el-input v-model="user.uName" />
			</el-form-item>
			<el-form-item label="密码">
				<el-input v-model="user.uPassword" type="password" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submitForm">登陆</el-button>
				<el-button @click="resetForm">Reset</el-button>
			</el-form-item>
		</el-form>
	</div>

</template>

<script setup>
	import {
		Menu as IconMenu,
		Message,
		Setting
	} from '@element-plus/icons-vue'
	import {
		ref,
		reactive
	} from 'vue'
	import axios from 'axios'
	import qs from 'qs'

	const show = ref(false);
	const user = reactive({
		uName: '',
		uPassword: '',
	})

	import {
		getCurrentInstance
	} from 'vue'
	const {
		proxy
	} = getCurrentInstance()

	const submitForm = () => {
		axios.post("http://localhost:8080/user/login", qs.stringify(user)).then(res => {
			console.log(res.data.msg == "false")
			console.log(res)
			if (res.data.msg == "false") {
				alert("用户名或者密码错误！")
				console.log(res.data)
				return
			}
			let user = res.data.obj
			// window.localStorage.token = token;
			proxy.$token.value = res.data.msg;
			proxy.$uName.value = user.uName;
			proxy.$uId.value = user.uId;
			proxy.$rId.value = user.rId;
			show.value = true;

		})
	}
</script>

<style scoped>
	.layout-container-demo .el-header {
		position: relative;
		background-color: var(--el-color-primary-light-7);
		color: var(--el-text-color-primary);
	}

	.layout-container-demo .el-aside {
		color: var(--el-text-color-primary);
		background: var(--el-color-primary-light-8);
	}

	.layout-container-demo .el-menu {
		border-right: none;
	}

	.layout-container-demo .el-main {
		padding: 15px;
	}

	.layout-container-demo .toolbar {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		height: 100%;
		right: 20px;
	}
</style>
